import pygame
import time
import sys
from pygame.locals import *
import random

import Arrow
import Bow

new=[]
i=0

pygame.init()
screen=pygame.display.set_mode((800,600),0,32)
bow=pygame.image.load('bow.bmp').convert()
screen.fill((255,255,255))
bow2=pygame.transform.flip(bow,True,False)
bow3=pygame.transform.flip(bow,True,True)
bow4=pygame.transform.flip(bow,False,True)
bow5=pygame.transform.rotate(bow,-30)
screen.blit(bow,(50,50))
screen.blit(bow2,(200,200))
screen.blit(bow3,(200,400))
screen.blit(bow4,(200,500))
screen.blit(bow5,(50,100))

alpha=random.randint(-30,30) #随机生成一个合适的出射角度
tmpPic=Arrow.Arrow(screen,bow,30) #先生成一支箭
tmpPic.image=pygame.transform.flip(tmpPic.image,False,True) #翻转到合适的角度
tmpPic.image=pygame.transform.rotate(tmpPic.image,alpha) #翻转到合适的角度
tmpPic.alpha=alpha+45
#arrowList1.append(tmpPic) #左上角射出的箭

screen.blit(tmpPic.image,(50,100))
pygame.display.update()
print('begin')
time.sleep(3)
sys.exit()








bow_topleft=Bow.Bow(screen,0,0)
bow_topright=Bow.Bow(screen,800,0)
bow_bottomleft=Bow.Bow(screen,0,600)
bow_bottomright=Bow.Bow(screen,800,600)
arrowList1=[]
arrowList2=[]
arrowList3=[]
arrowList4=[]
cont=0


dirx=random.randint(10,40)
diry=random.randint(10,40)
arrowList1.append(Arrow.Arrow(screen,bow_topleft,dirx,diry))
dirx=random.randint(-40,-10)
diry=random.randint(10,40)
arrowList2.append(Arrow.Arrow(screen,bow_topright,dirx,diry))
dirx=random.randint(10,40)
diry=random.randint(-40,-10)
arrowList3.append(Arrow.Arrow(screen,bow_bottomleft,dirx,diry))
dirx=random.randint(-40,-10)
diry=random.randint(-40,-10)
arrowList4.append(Arrow.Arrow(screen,bow_bottomright,dirx,diry))


while True:
    
    cont+=1
    if cont>5:
        dirx=random.randint(10,40)
        diry=random.randint(10,40)
        arrowList1.append(Arrow.Arrow(screen,bow_topleft,dirx,diry))
        dirx=random.randint(-40,-10)
        diry=random.randint(10,40)
        arrowList2.append(Arrow.Arrow(screen,bow_topright,dirx,diry))
        dirx=random.randint(10,40)
        diry=random.randint(-40,-10)
        arrowList3.append(Arrow.Arrow(screen,bow_bottomleft,dirx,diry))
        dirx=random.randint(-40,-10)
        diry=random.randint(-40,-10)
        arrowList4.append(Arrow.Arrow(screen,bow_bottomright,dirx,diry))
        cont=0
    time.sleep(0.1)
    
    for j in arrowList1:
        
        j.fly()
        if j.IsOut()==True:
             arrowList1.remove(j)
    for j in arrowList2:
        
        j.fly()
        if j.IsOut()==True:
             arrowList2.remove(j) 
    for j in arrowList3:
        
        j.fly()        
        if j.IsOut()==True:
            arrowList3.remove(j)
    for j in arrowList4:
       
        j.fly()
        if j.IsOut()==True:
            arrowList4.remove(j) 
    
    

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        elif event.type==KEYDOWN:
            if event.key==K_ESCAPE:
                pygame.quit()
                sys.exit()
            if event.key==K_p:
                print('p')

            
    screen.fill((255,255,255))
    
    for i in arrowList1:
        screen.blit(i.image,i.rect)
    for i in arrowList2:
        screen.blit(i.image,i.rect)
    for i in arrowList3:
        screen.blit(i.image,i.rect)
    for i in arrowList4:
        screen.blit(i.image,i.rect)
        
    screen.blit(bow_topleft.image,bow_topleft.rect)
    screen.blit(bow_topright.image,bow_topright.rect)
    screen.blit(bow_bottomleft.image,bow_bottomleft.rect)
    screen.blit(bow_bottomright.image,bow_bottomright.rect)
    pygame.display.update()







